package org.gwu.seuss.server.command;

import org.gwu.seuss.communication.request.ClientRequest;
import org.gwu.seuss.communication.request.ServerResponse;

/**
 * 
 * @author mmoran
 * 
 */
public class ShareCommand extends UserCommandBase implements Command {

	public ShareCommand(ClientRequest req) {
		super(req);
	}

	@Override
	public ServerResponse execute() throws Exception {
		String username = req.getUsername();
		String shareUsername = req.getUser().getUsername();
		log.info("User " + username + "requested to share file: "
				+ req.getFileId() + " with user: " + shareUsername);

		userService.authorizeUser(req);
		int result = fileService.shareFile(req);

		return getServerResponse(result, "file id: " + req.getFileId()
				+ " has been shared ");
	}
}